package com.spdzen.support;

import java.util.LinkedList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 日志工具类
 * 
 * @author accountwcx@qq.com
 *
 */
public class LogUtils {
	/**
	 * 全局通用日志
	 */
	private static final Logger COMMON_LOGGER = LoggerFactory.getLogger("spdzen.common");
	
	/**
	 * RequestInfo日志
	 */
	private static final Logger REQUEST_LOGGER = LoggerFactory.getLogger("spdzen.request");
	
	/**
	 * 获取全局通用日志
	 * @return
	 */
	public static Logger getLogger() {
		return COMMON_LOGGER;
	}
	
	public static Logger getRequestLogger() {
		return REQUEST_LOGGER;
	}
	
	public static void logRequest(RequestInfo info) {
		if(info.hasError()){
			REQUEST_LOGGER.error(JsonUtils.toJSONString(info));
		}else{
			REQUEST_LOGGER.info(JsonUtils.toJSONString(info));
		}
	}
	
	public static void logError(Throwable e, Object ...objects) {
		String message = "";
		if(objects != null && objects.length > 0){
			List<Object> list = new LinkedList<Object>();
			list.add(objects);
			message = JsonUtils.toJSONString(list);
		}
		
		COMMON_LOGGER.error(message, e);
	}
}
